package com.bocai.grainshop.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

//解决跨域的配置类  (注释掉renren-fast的跨域配置)
@Configuration
public class BocaiCorsConfiguration {

    @Bean
    public CorsWebFilter  corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        //配置跨域 放行任何请求头
        corsConfiguration.addAllowedHeader("*");
        //放行任何请求的类型
        corsConfiguration.addAllowedMethod("*");
        //放行任何的请求来源
        corsConfiguration.addAllowedOriginPattern("*");
        //允许带cookiee
        corsConfiguration.setAllowCredentials(true);
        //跨域所有请求
        source.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsWebFilter(source);
    }
}
